#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Purpose: Resource acces methods
# Created: 02/04/2009
# $Id $
# Copyright (c) 2008,2009 by University College London
# Authors:
# Didrik Pinte --<dpinte@dipole-consulting.com>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with HydroPlatform for details.

import os
import sys
import wx

import hydroplatform



if hasattr(sys, 'frozen'):
    BITMAPDIR = os.path.join( \
        os.path.normpath(os.path.dirname(sys.executable)), \
        "resources")
else:
    BITMAPDIR = os.path.join(hydroplatform.__path__[0], os.pardir, "resources")
    
BITMAP_EXTENSIONS = {wx.BITMAP_TYPE_XPM: ".xpm",
                     wx.BITMAP_TYPE_PNG: ".png",
                     wx.BITMAP_TYPE_JPEG: ".jpg",
                     wx.BITMAP_TYPE_ANY: ""}

def get_icon_path(filename, typename):
    '''
    returns the absolute path to the icon/image/resource needed)
    '''
    return os.path.join(BITMAPDIR, filename) + BITMAP_EXTENSIONS[typename]

def get_bitmap_resource(filename, typename):
    '''
    Returns the ressource as a wx.Bitmap object
    '''
    filename = get_icon_path(filename, typename)
    return wx.Bitmap(filename, typename)

def get_image_resource(filename, typename):
    '''
    Returns the resource as a wx.Image object
    '''
    filename = get_icon_path(filename, typename)
    return wx.Image(filename, typename)